package com.wechar_rpa.controller;

import com.wechar_rpa.model.SubscriptionPlan;
import com.wechar_rpa.model.UserSubscription;
import com.wechar_rpa.service.SubscriptionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/subscriptions")
public class SubscriptionController {

    @Autowired
    private SubscriptionService subscriptionService;

    @GetMapping("/{username}")
    public UserSubscription getUserSubscription(@PathVariable String username) {
        return subscriptionService.getUserSubscription(username);
    }

    @GetMapping("/plans/{level}")
    public SubscriptionPlan getPlanByLevel(@PathVariable int level) {
        return subscriptionService.getPlanByLevel(level);
    }

    @PostMapping("/subscribe")
    public void subscribeUser(@RequestParam String username, @RequestParam int planLevel) {
        subscriptionService.subscribeUser(username, planLevel);
    }
}